<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Returns a {@link pv.Vector} for the specified &lt;i>x&lt;/i> and &lt;i>y&lt;/i>
<span class='line'>  3</span>  * coordinate. This is a convenience factory method, equivalent to &lt;tt>new
<span class='line'>  4</span>  * pv.Vector(x, y)&lt;/tt>.
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * @see pv.Vector
<span class='line'>  7</span>  * @param {number} x the &lt;i>x&lt;/i> coordinate.
<span class='line'>  8</span>  * @param {number} y the &lt;i>y&lt;/i> coordinate.
<span class='line'>  9</span>  * @returns {pv.Vector} a vector for the specified coordinates.
<span class='line'> 10</span>  */</span><span class="WHIT">
<span class='line'> 11</span> </span><span class="NAME">pv.vector</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> </span><span class="COMM">/**
<span class='line'> 16</span>  * Constructs a {@link pv.Vector} for the specified &lt;i>x&lt;/i> and &lt;i>y&lt;/i>
<span class='line'> 17</span>  * coordinate. This constructor should not be invoked directly; use
<span class='line'> 18</span>  * {@link pv.vector} instead.
<span class='line'> 19</span>  *
<span class='line'> 20</span>  * @class Represents a two-dimensional vector; a 2-tuple &lt;i>&#x27e8;x,
<span class='line'> 21</span>  * y&#x27e9;&lt;/i>. The intent of this class is to simplify vector math. Note that
<span class='line'> 22</span>  * in performance-sensitive cases it may be more efficient to represent 2D
<span class='line'> 23</span>  * vectors as simple objects with &lt;tt>x&lt;/tt> and &lt;tt>y&lt;/tt> attributes, rather
<span class='line'> 24</span>  * than using instances of this class.
<span class='line'> 25</span>  *
<span class='line'> 26</span>  * @param {number} x the &lt;i>x&lt;/i> coordinate.
<span class='line'> 27</span>  * @param {number} y the &lt;i>y&lt;/i> coordinate.
<span class='line'> 28</span>  */</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="NAME">pv.Vector</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT">  </span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">  </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span> 
<span class='line'> 34</span> </span><span class="COMM">/**
<span class='line'> 35</span>  * Returns a vector perpendicular to this vector: &lt;i>&#x27e8;-y, x&#x27e9;&lt;/i>.
<span class='line'> 36</span>  *
<span class='line'> 37</span>  * @returns {pv.Vector} a perpendicular vector.
<span class='line'> 38</span>  */</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="NAME">pv.Vector.prototype.perp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">this.y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.x</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 42</span> 
<span class='line'> 43</span> </span><span class="COMM">/**
<span class='line'> 44</span>  * Returns a normalized copy of this vector: a vector with the same direction,
<span class='line'> 45</span>  * but unit length. If this vector has zero length this method returns a copy of
<span class='line'> 46</span>  * this vector.
<span class='line'> 47</span>  *
<span class='line'> 48</span>  * @returns {pv.Vector} a unit vector.
<span class='line'> 49</span>  */</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="NAME">pv.Vector.prototype.norm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">l</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.length</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.times</span><span class="PUNC">(</span><span class="NAME">l</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">l</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> 
<span class='line'> 55</span> </span><span class="COMM">/**
<span class='line'> 56</span>  * Returns the magnitude of this vector, defined as &lt;i>sqrt(x * x + y * y)&lt;/i>.
<span class='line'> 57</span>  *
<span class='line'> 58</span>  * @returns {number} a length.
<span class='line'> 59</span>  */</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="NAME">pv.Vector.prototype.length</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> 
<span class='line'> 64</span> </span><span class="COMM">/**
<span class='line'> 65</span>  * Returns a scaled copy of this vector: &lt;i>&#x27e8;x * k, y * k&#x27e9;&lt;/i>.
<span class='line'> 66</span>  * To perform the equivalent divide operation, use &lt;i>1 / k&lt;/i>.
<span class='line'> 67</span>  *
<span class='line'> 68</span>  * @param {number} k the scale factor.
<span class='line'> 69</span>  * @returns {pv.Vector} a scaled vector.
<span class='line'> 70</span>  */</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="NAME">pv.Vector.prototype.times</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">k</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">k</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> 
<span class='line'> 75</span> </span><span class="COMM">/**
<span class='line'> 76</span>  * Returns this vector plus the vector &lt;i>v&lt;/i>: &lt;i>&#x27e8;x + v.x, y +
<span class='line'> 77</span>  * v.y&#x27e9;&lt;/i>. If only one argument is specified, it is interpreted as the
<span class='line'> 78</span>  * vector &lt;i>v&lt;/i>.
<span class='line'> 79</span>  *
<span class='line'> 80</span>  * @param {number} x the &lt;i>x&lt;/i> coordinate to add.
<span class='line'> 81</span>  * @param {number} y the &lt;i>y&lt;/i> coordinate to add.
<span class='line'> 82</span>  * @returns {pv.Vector} a new vector.
<span class='line'> 83</span>  */</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="NAME">pv.Vector.prototype.plus</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">      </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">x.x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">x.y</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">      </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> 
<span class='line'> 90</span> </span><span class="COMM">/**
<span class='line'> 91</span>  * Returns this vector minus the vector &lt;i>v&lt;/i>: &lt;i>&#x27e8;x - v.x, y -
<span class='line'> 92</span>  * v.y&#x27e9;&lt;/i>. If only one argument is specified, it is interpreted as the
<span class='line'> 93</span>  * vector &lt;i>v&lt;/i>.
<span class='line'> 94</span>  *
<span class='line'> 95</span>  * @param {number} x the &lt;i>x&lt;/i> coordinate to subtract.
<span class='line'> 96</span>  * @param {number} y the &lt;i>y&lt;/i> coordinate to subtract.
<span class='line'> 97</span>  * @returns {pv.Vector} a new vector.
<span class='line'> 98</span>  */</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="NAME">pv.Vector.prototype.minus</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">      </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">x.x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">x.y</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">      </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Vector</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>104</span> 
<span class='line'>105</span> </span><span class="COMM">/**
<span class='line'>106</span>  * Returns the dot product of this vector and the vector &lt;i>v&lt;/i>: &lt;i>x * v.x +
<span class='line'>107</span>  * y * v.y&lt;/i>. If only one argument is specified, it is interpreted as the
<span class='line'>108</span>  * vector &lt;i>v&lt;/i>.
<span class='line'>109</span>  *
<span class='line'>110</span>  * @param {number} x the &lt;i>x&lt;/i> coordinate to dot.
<span class='line'>111</span>  * @param {number} y the &lt;i>y&lt;/i> coordinate to dot.
<span class='line'>112</span>  * @returns {number} a dot product.
<span class='line'>113</span>  */</span><span class="WHIT">
<span class='line'>114</span> </span><span class="NAME">pv.Vector.prototype.dot</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">      </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">x.x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">x.y</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">      </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span></pre></body></html>